package smedi.ismedi.web.bff.controller.safetycheck;

import cn.hutool.core.collection.CollectionUtil;
import com.smedi.ismedi.authority.starter.util.VerifyHelper;
import com.smedi.ismedi.constructionproject.api.dto.response.ProjectBasicResponse;
import com.smedi.ismedi.constructionproject.api.feign.RemoteConstructionProjectFeignApi;
import com.smedi.ismedi.file.dto.response.FileInfoResponse;
import com.smedi.ismedi.file.feign.RemoteFileFeignApi;
import com.smedi.ismedi.inmail.api.dto.request.ProcessTaskListRequest;
import com.smedi.ismedi.inmail.api.dto.response.ProcessTaskResponse;
import com.smedi.ismedi.inmail.api.feign.RemoteDataMiddlePlatformFeignApi;
import com.smedi.ismedi.inmail.api.feign.RemoteProcessFeignApi;
import com.smedi.ismedi.instrument.api.dto.request.hiddenDanger.QueryQualityHiddenDangerByOneRequest;
import com.smedi.ismedi.instrument.api.dto.request.hiddenDanger.QueryQualityHiddenDangerPageRequest;
import com.smedi.ismedi.instrument.api.dto.response.PersonResponse;
import com.smedi.ismedi.instrument.api.dto.response.hiddenDanger.QualityHiddenDangerResponse;
import com.smedi.ismedi.instrument.api.feign.RemoteQualityHiddenDangerFeignApi;
import com.smedi.ismedi.organization.api.dto.request.OrganizationListQueryRequest;
import com.smedi.ismedi.organization.api.dto.request.ProjectOrganizationListQueryRequest;
import com.smedi.ismedi.organization.api.dto.response.resp.OrganizationResp;
import com.smedi.ismedi.organization.api.dto.response.resp.ProjectOrganizationResp;
import com.smedi.ismedi.organization.api.feign.RemoteHrOrganizationFeignApi;
import com.smedi.ismedi.organization.api.feign.RemoteProjectOrganizationFeignApi;
import com.smedi.ismedi.safetycheck.dto.request.check.*;
import com.smedi.ismedi.safetycheck.dto.request.danger.QueryHiddenDangerByCheckRequest;
import com.smedi.ismedi.safetycheck.dto.response.PaginationResponse;
import com.smedi.ismedi.safetycheck.dto.response.check.SafetyCheckDetailResponse;
import com.smedi.ismedi.safetycheck.dto.response.check.SafetyCheckReplayResponse;
import com.smedi.ismedi.safetycheck.dto.response.check.SafetyCheckResponse;
import com.smedi.ismedi.safetycheck.dto.response.danger.HiddenDangerDetailResponse;
import com.smedi.ismedi.safetycheck.dto.response.danger.HiddenDangerResponse;
import com.smedi.ismedi.safetycheck.feign.RemoteHiddenDangerFeignApi;
import com.smedi.ismedi.safetycheck.feign.RemoteSafetyCheckFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import com.smedi.ismedi.web.starter.exception.LogicException;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import smedi.ismedi.web.bff.controller.BaseController;
import smedi.ismedi.web.bff.convert.Converter;
import smedi.ismedi.web.bff.dto.AvailableHiddenDangerBySafetyRequest;
import smedi.ismedi.web.bff.dto.HiddenDangerOperateDetailResponse;
import smedi.ismedi.web.bff.dto.HiddenDangerOperateResponse;
import smedi.ismedi.web.bff.dto.OrganizationResponse;
import smedi.ismedi.web.bff.dto.quality.QueryCheckHiddenDangerByOneRequest;
import smedi.ismedi.web.bff.dto.quality.RectificationRecordResponse;
import smedi.ismedi.web.bff.infrastructure.constant.ConstantField;
import smedi.ismedi.web.bff.infrastructure.constant.CustomError;
import smedi.ismedi.web.bff.infrastructure.constant.HiddenDangerField;
import smedi.ismedi.web.bff.infrastructure.util.FileHelper;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static smedi.ismedi.web.bff.infrastructure.constant.ConstantField.HiddenDangerSourceEnum.QLT;
import static smedi.ismedi.web.bff.infrastructure.constant.ConstantField.HiddenDangerSourceEnum.SFC;
import static smedi.ismedi.web.bff.infrastructure.constant.ConstantField.OrganizationTypeEnum.COMPANY;


/**
 * @Author Jimmy
 * @Date 2021/6/16 18:41
 */
@Api(tags = {"安全检查接口"})
@Slf4j
@RequestMapping(value = "/webbff/v1/")
@RestController
@RequiredArgsConstructor
public class SafetyCheckController extends BaseController {
    private final RemoteSafetyCheckFeignApi safetyCheckFeignApi;
    private final RemoteFileFeignApi fileFeignApi;
    private final RemoteHrOrganizationFeignApi remoteHrOrganizationFeignApi;
    private final RemoteProjectOrganizationFeignApi remoteProjectOrganizationFeignApi;
    private final RemoteDataMiddlePlatformFeignApi remoteDataMiddlePlatformFeignApi;
    private final RemoteConstructionProjectFeignApi remoteConstructionProjectFeignApi;

    private final RemoteHiddenDangerFeignApi remoteHiddenDangerFeignApi;

    private final RemoteQualityHiddenDangerFeignApi remoteQualityHiddenDangerFeignApi;

    private final Converter converter;

    private final RemoteProcessFeignApi processFeignApi;
    private final DozerUtil dozerUtil;

    @Value("${fdfs.service.address.in}")
    private String FDFS_SERVICE_ADDRESS_IN;

    @Value("${fdfs.service.address.out}")
    private String FDFS_SERVICE_ADDRESS_OUT;

    @ApiOperation(value = "安全检查维护", nickname = "安全检查维护")
    @PostMapping(value = "/safetyCheck")
    ResponseData<SafetyCheckResponse> safetyCheck(@RequestBody SafetyCheckRequest safetyCheckRequest) {
        return safetyCheckFeignApi.saveSafetyCheck(safetyCheckRequest);
    }

    @ApiOperation(value = "安全检查删除", nickname = "安全检查删除")
    @DeleteMapping(value = "/safetyCheck/deleteSafetyCheck")
    ResponseData<Boolean> deleteSafetyCheck(@RequestParam("safetyCheckIds") List<Long> ids) {
        return safetyCheckFeignApi.deleteSafetyCheck(ids);
    }

    /**
     * 安全检查回复
     *
     * @param safetyCheckReplayRequest
     * @return
     */
    @ApiOperation(value = "安全检查回复", nickname = "安全检查回复")
    @PostMapping(value = "/safetyCheck/safetyCheckReplay")
    ResponseData<SafetyCheckReplayResponse> safetyCheckReplay(@Validated @ApiParam(value = "param", required = true) @RequestBody SafetyCheckReplayRequest safetyCheckReplayRequest) {
        return safetyCheckFeignApi.safetyCheckReplay(safetyCheckReplayRequest);
    }

    /**
     * web端安全检查查询
     *
     * @param webSearchSafetyCheckRequest
     * @return
     */
    @ApiOperation(value = "web端安全检查查询", nickname = "web端安全检查查询")
    @GetMapping(value = "/safetyCheckQuery/webSearchSafetyCheck")
    ResponseData<PaginationResponse<SafetyCheckResponse>> webSearchSafetyCheck(@Validated @SpringQueryMap WebSearchSafetyCheckRequest webSearchSafetyCheckRequest) {
        return safetyCheckFeignApi.webSearchSafetyCheck(webSearchSafetyCheckRequest);
    }

    /**
     * 安全检查详情查询
     *
     * @param safetyCheckId
     * @return
     */
    @ApiOperation(value = "安全检查详情查询", nickname = "安全检查详情查询")
    @GetMapping(value = "/safetyCheckQuery/searchSafetyCheckDetail")
    ResponseData<SafetyCheckDetailResponse> searchSafetyCheckDetail(@RequestParam("safetyCheckId") Long safetyCheckId) {
        return safetyCheckFeignApi.searchSafetyCheckDetail(safetyCheckId);
    }

    /**
     * 导出单个安全检查
     *
     * @param id
     * @return
     * @throws IOException
     */
    @ApiOperation(httpMethod = "GET", value = "预览单个安全检查")
    @GetMapping(value = "/previewSafetyCheck")
    public ResponseData<String> previewSafetyCheck(@RequestParam("id") Long id, HttpServletResponse response) throws IOException {
        String signKey = safetyCheckFeignApi.exportSafetyCheck(id).getData();
        FileInfoResponse fileInfoResponse = fileFeignApi.getFileInfo(signKey).getData();
        String url = FileHelper.getUrl(FDFS_SERVICE_ADDRESS_OUT, fileInfoResponse.getStorageGroup(), fileInfoResponse.getPath(), fileInfoResponse.getName(), response);
        return new ResponseData<>().success(url);
    }

    @ApiOperation(httpMethod = "POST", value = "预览多个安全检查")
    @PostMapping(value = "/previetSafetyCheckBatch")
    public ResponseData<String> previewSafetyCheckBatch(@Validated @RequestBody WebSearchSafetyCheckRequest webSearchSafetyCheckRequest, HttpServletResponse response) throws IOException {
        String signKey = safetyCheckFeignApi.exportSafetyCheckBatch(webSearchSafetyCheckRequest).getData();
        FileInfoResponse fileInfoResponse = fileFeignApi.getFileInfo(signKey).getData();
        String url = FileHelper.getUrl(FDFS_SERVICE_ADDRESS_OUT, fileInfoResponse.getStorageGroup(), fileInfoResponse.getPath(), fileInfoResponse.getName(), response);

        return new ResponseData<>().success(url);
    }

    /**
     * 导出单个安全检查
     *
     * @param id
     * @return
     * @throws IOException
     */
    @ApiOperation(httpMethod = "GET", value = "导出单个安全检查")
    @GetMapping(value = "/exportSafetyCheck")
    public ResponseData<Boolean> exportSafetyCheck(@RequestParam("id") Long id, HttpServletResponse response) throws IOException {
        String signKey = safetyCheckFeignApi.exportSafetyCheck(id).getData();
        FileInfoResponse fileInfoResponse = fileFeignApi.getFileInfo(signKey).getData();
        FileHelper.downloadFile(FDFS_SERVICE_ADDRESS_IN, fileInfoResponse.getStorageGroup(), fileInfoResponse.getPath(), fileInfoResponse.getName(), response);

        return new ResponseData<>().success(true);
    }

    @ApiOperation(httpMethod = "POST", value = "导出多个安全检查")
    @PostMapping(value = "/exportSafetyCheckBatch")
    public ResponseData<Boolean> exportSafetyCheckBatch(@Validated @RequestBody WebSearchSafetyCheckRequest webSearchSafetyCheckRequest, HttpServletResponse response) {
        String signKey = safetyCheckFeignApi.exportSafetyCheckBatch(webSearchSafetyCheckRequest).getData();
        FileInfoResponse fileInfoResponse = fileFeignApi.getFileInfo(signKey).getData();
        FileHelper.downloadFile(FDFS_SERVICE_ADDRESS_IN, fileInfoResponse.getStorageGroup(), fileInfoResponse.getPath(), fileInfoResponse.getName(), response);

        return new ResponseData<>().success(true);
    }

    /**
     * 审批确认
     */
    @ApiOperation(value = "审批确认", nickname = "审批确认")
    @PostMapping(value = "/getFixSafetyCheckHistoryStatus")
    ResponseData<Boolean> postApprovalConfirmation(@Validated @RequestBody SafetyCheckApproveRequest safetyCheckApproveRequest) {
        return safetyCheckFeignApi.postApprovalConfirmation(safetyCheckApproveRequest);
    }

    /**
     * 获取项目所属的检查单位
     */
    @ApiOperation(value = "获取项目所属的检查单位", nickname = "获取项目所属的检查单位")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目id", dataType = "Long", dataTypeClass = Long.class),
    })
    @GetMapping(value = "/safetyCheckOrganization")
    ResponseData<List<OrganizationResponse>> getSafetyCheckOrganization(@Validated @RequestParam Long projectId) {
        List<OrganizationResponse> organizationResponses = new ArrayList<>();

        //List<OrganizationResp> organizations = remoteHrOrganizationFeignApi.getOrganizationList(OrganizationListQueryRequest.builder().projectId(projectId).typeList(new ArrayList<>(Arrays.asList(COMPANY.name(),PROJECT_MANAGEMENT_ORGANIZATION.name()))).build()).getData();
        List<OrganizationResp> organizations = remoteHrOrganizationFeignApi.getOrganizationList(OrganizationListQueryRequest.builder().projectId(projectId).typeOr(COMPANY.name()).build()).getData();

        List<ProjectOrganizationResp> projectOrganizations = remoteProjectOrganizationFeignApi.getProjectOrganizationList(ProjectOrganizationListQueryRequest.builder().projectId(projectId).build()).getData();

        organizations = organizations.stream().sorted(Comparator.comparing(OrganizationResp::getDisplayOrder)).collect(Collectors.toList());

        if (!organizations.isEmpty()) {
            List<OrganizationResponse> organizationResponseTemps = new ArrayList<>(organizations.size());
            for (OrganizationResp hrOrganizationResp : organizations) {
                OrganizationResponse organizationResponseTemp = new OrganizationResponse();
                organizationResponseTemp.setOrganizationId(hrOrganizationResp.getId());
                organizationResponseTemp.setFullName(hrOrganizationResp.getFullName());
                organizationResponseTemp.setShortName(hrOrganizationResp.getShortName());
                organizationResponseTemp.setType(hrOrganizationResp.getType());
                organizationResponseTemps.add(organizationResponseTemp);
            }
            organizationResponses.addAll(organizationResponseTemps);
        }

        if (!projectOrganizations.isEmpty()) {
            List<OrganizationResponse> organizationResponseTemps = new ArrayList<>(projectOrganizations.size());
            for (ProjectOrganizationResp projectOrganizationResp : projectOrganizations) {
                OrganizationResponse organizationResponseTemp = new OrganizationResponse();
                organizationResponseTemp.setOrganizationId(projectOrganizationResp.getId());
                organizationResponseTemp.setFullName(projectOrganizationResp.getFullName());
                organizationResponseTemp.setShortName(projectOrganizationResp.getShortName());
                organizationResponseTemp.setType(projectOrganizationResp.getType());
                organizationResponseTemps.add(organizationResponseTemp);
            }
            organizationResponses.addAll(organizationResponseTemps);
        }

        return new ResponseData<>().success(organizationResponses);
    }

    /**
     * 查询天气
     *
     * @param projectId 项目Id
     * @param date     日期
     * @return ResponseData<String> 天气
     */
    @ApiOperation(httpMethod = "GET", value = "获取天气")
    @GetMapping(value = "/weather")
    ResponseData<String> getWeather(@RequestParam(value = "projectId") Long projectId,
                                    @RequestParam(value = "date") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {

        ResponseData<ProjectBasicResponse> queryProjectBasicView = remoteConstructionProjectFeignApi.getQueryProjectBasicView(projectId);
        if (!queryProjectBasicView.isSuccess()){
            return new ResponseData<>().success("多云");
        }
        String cityName = queryProjectBasicView.getData().getProjectAddressCity();
        ResponseData<String> weatherResponse = remoteDataMiddlePlatformFeignApi.getWeather(cityName, date);
        String weather = weatherResponse.getData();

        if(StringUtils.isEmpty(weather)){
            return new ResponseData<>().success("多云");
        }

        return new ResponseData<>().success(weather);
    }

    /**
     *带队负责人修改检查
     */
    @ApiOperation(value = "带队负责人修改检查信息", nickname = "带队负责人修改检查信息")
    @PostMapping(value = "/updateCheckByTeamLeader")
    ResponseData<Boolean> updateCheckByTeamLeader(@Validated @RequestBody UpdateCheckByTeamLeaderRequest updateCheckByTeamLeaderRequest){
        return safetyCheckFeignApi.updateCheckByTeamLeader(updateCheckByTeamLeaderRequest);
    }

    /**
     *
     * 隐患详情查询（兼容安全与质量模块）
     */
    @ApiOperation(value = "隐患详情查询（兼容安全与质量模块）", nickname = "安全隐患详情查询")
    @PostMapping(value = "/searchHiddenDangerDetail")
    ResponseData<HiddenDangerOperateDetailResponse> searchHiddenDangerDetail(@Validated @RequestBody QueryCheckHiddenDangerByOneRequest queryCheckHiddenDangerByOneRequest) {
        HiddenDangerOperateDetailResponse hiddenDangerOperateDetailResponse = new HiddenDangerOperateDetailResponse();
        if (SFC.name().equals(queryCheckHiddenDangerByOneRequest.getHiddenDangerSource())) {
            ResponseData<HiddenDangerDetailResponse> responseResponseData = remoteHiddenDangerFeignApi.searchHiddenDangerDetail(queryCheckHiddenDangerByOneRequest.getHiddenDangerId());

            HiddenDangerDetailResponse response = responseResponseData.getData();
            hiddenDangerOperateDetailResponse = dozerUtil.convertor(response, HiddenDangerOperateDetailResponse.class);

            Map<String, Map<String, Object>> detailInfo = response.getDetailInfo();
            List<HiddenDangerOperateResponse> hiddenDangerOperateResponses = new ArrayList<>();
            for (String date : detailInfo.keySet()) {
                HiddenDangerOperateResponse operateResponse = new HiddenDangerOperateResponse();
                if (date.contains(" ")) {
                    operateResponse.setOperateTime(LocalDateTime.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                } else {
                    operateResponse.setOperateTime(LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay());
                }
                Map<String, Object> objectMap = detailInfo.get(date);
                for (String name : objectMap.keySet()) {
                    operateResponse.setOperateName(name);
                    operateResponse.setOperateInfo(objectMap.get(name));
                }
                hiddenDangerOperateResponses.add(operateResponse);
            }

            List<HiddenDangerOperateResponse> hiddenDangerOperateResponsesSort = hiddenDangerOperateResponses.stream().sorted(Comparator.comparing(HiddenDangerOperateResponse::getOperateTime)).collect(Collectors.toList());

            hiddenDangerOperateDetailResponse.setOperateResponses(hiddenDangerOperateResponsesSort);
        } else if (QLT.name().equals(queryCheckHiddenDangerByOneRequest.getHiddenDangerSource())) {
            ResponseData<QualityHiddenDangerResponse> qualityHiddenDangerResponse = remoteQualityHiddenDangerFeignApi.queryQualityHiddenDangerByOne(QueryQualityHiddenDangerByOneRequest.builder().id(queryCheckHiddenDangerByOneRequest.getHiddenDangerId()).build());
            hiddenDangerOperateDetailResponse = converter.qualityHiddenDangerResponseToHiddenDangerOperateDetailResponse(qualityHiddenDangerResponse.getData());

            if (VerifyHelper.isAvailable(qualityHiddenDangerResponse)) {
                List<HiddenDangerOperateResponse> hiddenDangerOperateResponses = new ArrayList<>();
                ResponseData<List<ProcessTaskResponse>> listResponseData = processFeignApi.getProcessTaskList(ProcessTaskListRequest.builder()
                        .businessCode(String.valueOf(qualityHiddenDangerResponse.getData().getId()))
                        .businessType("QLT_HIDDEN_DANGER")
                        .processDefinitionKey("PROCESS_QLT_HIDDENDANGER_RECTIFICATION")
                        .build());
                if (listResponseData.isSuccess() && CollectionUtil.isNotEmpty(listResponseData.getData())) {
                    com.smedi.ismedi.safetycheck.dto.response.PersonResponse  lastOperatePerson= hiddenDangerOperateDetailResponse.getLastOperatePerson();
                    List<ProcessTaskResponse> processTaskResponses = listResponseData.getData();
                    for (ProcessTaskResponse processTaskResponse : processTaskResponses) {
                        HiddenDangerOperateResponse operateResponse = new HiddenDangerOperateResponse();
                        if (null != processTaskResponse.getEndTime() &&
                                ("ACTIVITY_HIDDENDANGER_RECTIFICATION".equals(processTaskResponse.getTaskDefinitionKey())
                                        || "ACTIVITY_HIDDENDANGER_REVIEW".equals(processTaskResponse.getTaskDefinitionKey()))) {
                            RectificationRecordResponse rectificationRecord = new RectificationRecordResponse();
                            Long ownerId = null;
                            String ownername = "";
                            String job = "";
                            String result = "";
                            if (null != processTaskResponse.getOwner()) {
                                ownerId = processTaskResponse.getOwner().getId();
                                ownername = processTaskResponse.getOwner().getName();
                            }
                            Map<String, String> variables = processTaskResponse.getVariables();
                            for (String name : variables.keySet()) {
                                if ("PERSONJOB".equals(name)) {
                                    job = variables.get(name);
                                }
                                if ("METHOD".equals(name)) {
                                    result = variables.get(name);
                                }
                            }
                            lastOperatePerson.setName(ownername);
                            lastOperatePerson.setPersonId(ownerId);
                            lastOperatePerson.setLatestUpdatedDate(processTaskResponse.getEndTime());
                            rectificationRecord.setId(processTaskResponse.getId());
                            rectificationRecord.setTaskDefinitionKey(processTaskResponse.getTaskDefinitionKey());
                            rectificationRecord.setName(processTaskResponse.getName());
                            rectificationRecord.setStartTime(processTaskResponse.getStartTime());
                            rectificationRecord.setEndTime(processTaskResponse.getEndTime());
                            rectificationRecord.setReviewResult(result);
                            rectificationRecord.setPersonResponse(new PersonResponse(ownerId, ownername, job));
                            rectificationRecord.setComments(processTaskResponse.getComments());
                            rectificationRecord.setFileResponse(processTaskResponse.getFiles());
                            String operateName="整改";
                            if("ACTIVITY_HIDDENDANGER_REVIEW".equals(processTaskResponse.getTaskDefinitionKey())){
                                operateName="复查";
                            }
                            operateResponse.setOperateName(operateName);
                            operateResponse.setOperateTime(processTaskResponse.getEndTime());
                            operateResponse.setOperateInfo(rectificationRecord);
                            hiddenDangerOperateResponses.add(operateResponse);
                        }
                    }
                    hiddenDangerOperateDetailResponse.setLastOperatePerson(lastOperatePerson);
                    hiddenDangerOperateDetailResponse.setOperateResponses(hiddenDangerOperateResponses);
                }
            }

        }
        return new ResponseData<>().success(hiddenDangerOperateDetailResponse);
    }

    @ApiOperation(value = "安全检查-可关联隐患列表查询", nickname = "安全检查-关联隐患列表查询")
    @PostMapping(value = "/queryAvailableHiddenDangerListBySafety")
    ResponseData<PaginationData<HiddenDangerResponse>> queryAvailableHiddenDangerListBySafety(@Validated @RequestBody AvailableHiddenDangerBySafetyRequest availableHiddenDangerBySafetyRequest) {
        if (ConstantField.HiddenDangerSourceEnum.QLT.name().equals(availableHiddenDangerBySafetyRequest.getHiddenDangerSource())) {
            QueryQualityHiddenDangerPageRequest queryQualityHiddenDangerPageRequest = converter.availableHiddenDangerBySafetyRequestToQueryQualityHiddenDangerPageRequest(availableHiddenDangerBySafetyRequest);
            queryQualityHiddenDangerPageRequest.setAvailable(true);
            if(null != queryQualityHiddenDangerPageRequest.getTaskStatus()){
                queryQualityHiddenDangerPageRequest.setTaskStatus(HiddenDangerField.StatusEnum.getValue(queryQualityHiddenDangerPageRequest.getTaskStatus()));
            }
            if(null != queryQualityHiddenDangerPageRequest.getCheckType()){
                queryQualityHiddenDangerPageRequest.setCheckType(HiddenDangerField.StatusEnum.getValue(queryQualityHiddenDangerPageRequest.getCheckType()));
            }
            if(null != queryQualityHiddenDangerPageRequest.getHiddenDangerType()){
                queryQualityHiddenDangerPageRequest.setHiddenDangerType(HiddenDangerField.StatusEnum.getValue(queryQualityHiddenDangerPageRequest.getHiddenDangerType()));
            }
            ResponseData<PaginationData<QualityHiddenDangerResponse>> responseData = remoteQualityHiddenDangerFeignApi.queryQualityHiddenDangerPage(queryQualityHiddenDangerPageRequest);
            if(responseData.isSuccess()){
                return new ResponseData<PaginationData<HiddenDangerResponse>>().success(converter.qualityHiddenDangerResponseToHiddenDangerResponse(responseData.getData()));
            }else{
                throw LogicException.raise(CustomError.CALL_REMOTE_API_ERROR, responseData.getApplication(), String.valueOf(responseData.getErrorMsg()));
            }
        } else if (ConstantField.HiddenDangerSourceEnum.SFC.name().equals(availableHiddenDangerBySafetyRequest.getHiddenDangerSource())) {
            QueryHiddenDangerByCheckRequest queryHiddenDangerByCheckRequest = converter.availableHiddenDangerBySafetyRequestToQueryHiddenDangerByCheckRequest(availableHiddenDangerBySafetyRequest);
            queryHiddenDangerByCheckRequest.setAvailable(true);
            ResponseData<PaginationData<HiddenDangerResponse>> responseData = remoteHiddenDangerFeignApi.queryHiddenDangerListByCheck(queryHiddenDangerByCheckRequest);
            if(responseData.isSuccess()){
                return new ResponseData<PaginationResponse<HiddenDangerResponse>>().success(responseData.getData());
            }else{
                throw LogicException.raise(CustomError.CALL_REMOTE_API_ERROR, responseData.getApplication(), String.valueOf(responseData.getErrorMsg()));
            }
        } else {
            return null;
        }
    }
}
